﻿using ByteSite.Service.Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace ByteSite.Service
{
    public class TaskManagerService
    {
        readonly Timer _timer;

        public TaskManagerService()
        {
            _timer = new Timer(1000) { AutoReset = true };
            _timer.Elapsed += (sender, eventArgs) => Console.WriteLine("It is {0} and all is well", DateTime.Now);
        }

        public void Start() { _timer.Start(); }
        public void Stop() { _timer.Stop(); }
    }
    /// <summary>
    /// QuartZ定时
    /// </summary>
    public class QuartzManage
    {
        public void Start()
        {
            QuartzHelper.InitScheduler();
            QuartzHelper.StartScheduler();
        }

        public Task<bool> Pause(string groupName, string jobName)
        {
            return QuartzHelper.PauseSchedule(groupName, jobName);
        }

        public Task<bool> Resume(string groupName, string jobName)
        {
            return QuartzHelper.ResumeSchedule(groupName, jobName);
        }

        public Task<bool> Remove(string groupName, string jobName)
        {
            return QuartzHelper.RemoveSchedule(groupName, jobName);
        }

        public Task<string> Get(string groupName, string jobName)
        {
            return QuartzHelper.GetSchedule(groupName, jobName);
        }

        public void Stop()
        {
            QuartzHelper.StopSchedule();
            System.Environment.Exit(0);
        }
    }
}
